package com.aner.test.controller;

import com.aner.test.domain.CommonResult;
import com.aner.test.security.LoginParam;
import com.aner.test.security.service.LoginService;
import com.aner.test.security.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * login controller
 * 
 * @author aner
 */
@RestController
public class LoginController
{
    @Autowired
    private LoginService loginService;

    /**
     * login
     * 
     * @param loginUser
     * @return
     */
    @PostMapping("/login")
    public CommonResult login(@RequestBody LoginParam loginUser)
    {
        CommonResult result = CommonResult.success();
        // create token
        String token = loginService.login(loginUser.getUsername(), loginUser.getPassword());
        result.put(TokenService.TOKEN, token);
        return result;
    }
}
